package com.example.uit_management;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;

import android.R.string;
import android.util.Log;
import android.widget.Toast;
/** Theo tác trên sever Course(Các môn học trong học kì)	 */
public class JsonParser_course {
	//////////////////////////////////////////////////////////
	//Các key trong Json
	/**Key  Tên môn học */
	static final String KEY_subjectName = "subjectName"; // parent node
	/**Key Số lượng đã đăng kí  */
	static final String KEY_courseSize = "courseSize";
	/**Key Tên giáo viên  */
	static final String KEY_lecturerName = "lecturerName";
	/**Key Mã khoa  */
	static final String KEY_facultyID = "facultyID";
	/**Key Lịch học  */
	static final String KEY_schedule = "schedule";
	/**Key Số tính chỉ lý thuyết */
	static final String KEY_subjectTheory = "subjectTheory";
	/**Key Thứ trong tuần  */
	static final String KEY_courseDay = "courseDay";
	/**Key Mã lớp học */
	static final  String KEY_courseID = "courseID";
	/**Key Mã môn học  */
	static final  String KEY_subjectID = "subjectID";
	/**Key Mã ????  */
	static final  String KEY_lecturerID = "lecturerID";	
	/**Key Trạng thái đăng kí  */
	static final  String KEY_courseStatus = "courseStatus";	
	/**Key Ca học  */
	static final  String KEY_courseTime = "courseTime";	
	/**Key Mã ?????  */
	static final  String KEY_semesterID = "semesterID";	
	/**Key Môn lý thuyết hay thực hành  */
	static final  String KEY_courseType = "courseType";	
	/**Key Số lượng đăng kí tối đa  */
	static final  String KEY_courseMaxSize = "courseMaxSize";	
	/**Key Số phòng  */
	static final  String KEY_roomID = "roomID";	
	/**Key số tính chỉ thực hành  */
	static final  String KEY_subjectPractice = "subjectPractice";	
	/**Key năm học  */
	static final  String KEY_semesterYear = "semesterYear";	
	/**Key học kì   */
	static final  String KEY_semesterIndex = "semesterIndex";	
	
	/**Hàm khỏi tạo  JsonParser_course*/
	public JsonParser_course() {
		// TODO Auto-generated constructor stub
	}
	/** Dữ liệu trả về là Array Json ta cần*/
	public JSONArray GetJSONArray_course(){		
		String readTwitterFeed = readTwitterFeed();					
			try
	        {
				JSONObject json = new JSONObject(readTwitterFeed);
				JSONArray jsonArray = json.getJSONArray("data");	
				return jsonArray;
	        }
	        catch (Exception je)
	        {	          
	        	return null;
	        }	  				
	}
	/** Dữ liệu trả về là Array Json ta cần theo hoc ky*/
	public JSONArray GetJSONArray_course_semester(String semester){		
		String readTwitterFeed = readTwitterFeed_semester(semester);					
			try
	        {
				JSONObject json = new JSONObject(readTwitterFeed);
				JSONArray jsonArray = json.getJSONArray("data");	
				return jsonArray;
	        }
	        catch (Exception je)
	        {	          
	        	return null;
	        }	  				
	}
	/**
	get Json OB ject with other String
	*/
	public JSONArray GetJSONArray_String(String readTwitterFeed){					
			try
	        {
				JSONObject json = new JSONObject(readTwitterFeed);
				JSONArray jsonArray = json.getJSONArray("data");	
				return jsonArray;
	        }
	        catch (Exception je)
	        {	          
	        	return null;
	        }	  				
	}
	/**Lay Json từ sever JsonParser_Course(các môn mở trong học kì này) */
	public String readTwitterFeed() {
	    StringBuilder builder = new StringBuilder();
	    HttpClient client = new DefaultHttpClient();
	    HttpGet httpGet = new HttpGet("http://uitstudentmanagement.appspot.com/course?type=openfull");
	    try {
	        HttpResponse response = client.execute(httpGet);
	        StatusLine statusLine = response.getStatusLine();
	        int statusCode = statusLine.getStatusCode();
	        if (statusCode == 200) {
	            HttpEntity entity = response.getEntity();
	            InputStream content = entity.getContent();
	            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
	            String line;
	            while ((line = reader.readLine()) != null) {
	                builder.append(line);
	            }
	        } else {
	            Log.e(JsonParser_course.class.toString(), "Method GetJSONArray_regCourse of JsonParser_course");
	        }
	    } catch (ClientProtocolException e) {
	        e.printStackTrace();
	    } catch (IOException e) {
	        e.printStackTrace();
	    }
	    return builder.toString();
	}
	/**Lay Json từ sever JsonParser_Course(các môn mở theo hoc ky) */
	public String readTwitterFeed_semester(String semester) {
	    StringBuilder builder = new StringBuilder();
	    HttpClient client = new DefaultHttpClient();
	    HttpGet httpGet = new HttpGet("http://uitstudentmanagement.appspot.com/course?type=semester&value="+semester);
	    try {
	        HttpResponse response = client.execute(httpGet);
	        StatusLine statusLine = response.getStatusLine();
	        int statusCode = statusLine.getStatusCode();
	        if (statusCode == 200) {
	            HttpEntity entity = response.getEntity();
	            InputStream content = entity.getContent();
	            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
	            String line;
	            while ((line = reader.readLine()) != null) {
	                builder.append(line);
	            }
	        } else {
	            Log.e(JsonParser_course.class.toString(), "Method GetJSONArray_regCourse of JsonParser_course");
	        }
	    } catch (ClientProtocolException e) {
	        e.printStackTrace();
	    } catch (IOException e) {
	        e.printStackTrace();
	    }
	    return builder.toString();
	}

	/**
	 Get Map STring swith key facultyID
	 */
	public ArrayList<HashMap<String, String>> getMapKey(String Key)
	{
		ArrayList<HashMap<String, String>> ArrayMap = new ArrayList<HashMap<String, String>>();
		JSONArray jsonArray = GetJSONArray_course();
		// looping through all jsonarray nodes 
		for (int i = 0; i < jsonArray.length(); i++) {
			try {
				//create new JsonObject	
				JSONObject js = jsonArray.getJSONObject(i);
				if(js.getString("facultyID").equals(Key) ){					
				
				if( js.getString("courseStatus").equals("Mở")||js.getString("courseStatus").equals("Đầy")){
				// creating new HashMap
				HashMap<String, String> map = new HashMap<String, String>();
				String data;
				Log.e(JsonParser_course.class.toString(), "GetMap_full method----------------");
				data		=js.getString("subjectName");
				map.put(KEY_subjectName, data);
				//Log.e(JsonParser_course.class.toString(), "Get string subjectName");
				data		=js.getString("courseSize");
				map.put(KEY_courseSize, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseSize");
				data		=js.getString("lecturerName");
				map.put(KEY_lecturerName, data);
				Log.e(JsonParser_course.class.toString(), "Get string lecturerName" +data);
				data		=js.getString("facultyID");
				map.put(KEY_facultyID, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string facultyID");				
				data		=js.getString("subjectTheory");
				map.put(KEY_subjectTheory, data);
				//Log.e(JsonParser_course.class.toString(), "Get string subjectTheory");
				data		=js.getString("courseDay");
				map.put(KEY_courseDay, data);	
				Log.e(JsonParser_course.class.toString(), "Get string courseDay " +data);
				data		=js.getString("courseID");
				map.put(KEY_courseID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseID");
				data		=js.getString("subjectID");
				map.put(KEY_subjectID, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string subjectID");
				data		=js.getString("lecturerID");
				map.put(KEY_lecturerID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string lecturerID");
				data		=js.getString("courseStatus");
				map.put(KEY_courseStatus, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseStatus");
				data		=js.getString("courseTime");
				map.put(KEY_courseTime, data);
				Log.e(JsonParser_course.class.toString(), "Get string courseTime :"+data);	
				data		=js.getString("semesterID");
				map.put(KEY_semesterID, data);					
				//Log.e(JsonParser_course.class.toString(), "Get string semesterID");	
				data		=js.getString("courseType");
				map.put(KEY_courseType, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseType");	
				data		=js.getString("courseMaxSize");
				map.put(KEY_courseMaxSize, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseMaxSize");	
				data		=js.getString("roomID");
				map.put(KEY_roomID, data);
				Log.e(JsonParser_course.class.toString(), "Get string roomID:" +data);					
				data		=js.getString("subjectPractice");
				map.put(KEY_subjectPractice, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string subjectPractice");	
				data		=js.getString("semesterYear");
				map.put(KEY_semesterYear, data);
				//Log.e(JsonParser_course.class.toString(), "Get string semesterYear");
				data		=js.getString("semesterIndex");
				map.put(KEY_semesterIndex, data);
				//Log.e(JsonParser_course.class.toString(), "Get string facultyID");
				data		="Thu "+js.getString("courseDay")+ "Ca "+js.getString("courseTime")+"Phong "+js.getString("roomID");
				map.put(KEY_schedule, data);				
				// Add a HashMap into Array HashMap
				ArrayMap.add(map);	
				}
				}
			} catch (Exception e) {
				// TODO: handle exception
				Log.e(JsonParser_course.class.toString(), "Excetion getMapKey method");
			}
			
		}		
		return ArrayMap;
	}
	/**
	 Get Map STring swith key
	 */
	public ArrayList<HashMap<String, String>> getMapKey_KEY(String KEY_MAP,String KEY_INDEX)
	{
		ArrayList<HashMap<String, String>> ArrayMap = new ArrayList<HashMap<String, String>>();
		JSONArray jsonArray = GetJSONArray_course();
		// looping through all jsonarray nodes 
		for (int i = 0; i < jsonArray.length(); i++) {
			try {
				//create new JsonObject	
				JSONObject js = jsonArray.getJSONObject(i);
				if(js.getString(KEY_MAP).equals(KEY_INDEX)){
				// creating new HashMap
				HashMap<String, String> map = new HashMap<String, String>();
				String data;
				// adding each child node to HashMap key => value
				data		=js.getString("subjectName");
				map.put(KEY_subjectName, data);
				//Log.e(JsonParser_course.class.toString(), "Get string subjectName");
				data		=js.getString("courseSize");
				map.put(KEY_courseSize, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseSize");
				data		=js.getString("lecturerName");
				map.put(KEY_lecturerName, data);
				//Log.e(JsonParser_course.class.toString(), "Get string lecturerName");
				data		=js.getString("facultyID");
				map.put(KEY_facultyID, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string facultyID");				
				data		=js.getString("subjectTheory");
				map.put(KEY_subjectTheory, data);
				//Log.e(JsonParser_course.class.toString(), "Get string subjectTheory");
				data		=js.getString("courseDay");
				map.put(KEY_courseDay, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseDay");
				data		=js.getString("courseID");
				map.put(KEY_courseID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseID");
				data		=js.getString("subjectID");
				map.put(KEY_subjectID, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string subjectID");
				data		=js.getString("lecturerID");
				map.put(KEY_lecturerID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string lecturerID");
				data		=js.getString("courseStatus");
				map.put(KEY_courseStatus, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseStatus");
				data		=js.getString("courseTime");
				map.put(KEY_courseTime, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseTime");	
				data		=js.getString("semesterID");
				map.put(KEY_semesterID, data);					
				//Log.e(JsonParser_course.class.toString(), "Get string semesterID");	
				data		=js.getString("courseType");
				map.put(KEY_courseType, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseType");	
				data		=js.getString("courseMaxSize");
				map.put(KEY_courseMaxSize, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseMaxSize");	
				data		=js.getString("roomID");
				map.put(KEY_roomID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string roomID");					
				data		=js.getString("subjectPractice");
				map.put(KEY_subjectPractice, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string subjectPractice");	
				data		=js.getString("semesterYear");
				map.put(KEY_semesterYear, data);
				//Log.e(JsonParser_course.class.toString(), "Get string semesterYear");
				data		=js.getString("semesterIndex");
				map.put(KEY_semesterIndex, data);
				//Log.e(JsonParser_course.class.toString(), "Get string semesterIndex");	
	
									
				
				ArrayMap.add(map);	
				}
			} catch (Exception e) {
				// TODO: handle exception
				//Log.e(JsonParser_course.class.toString(), "Excetion getMapKey method");
			}
			
		}		
		return ArrayMap;
	}
	/**
	 Get Map STring swith key other String Json
	 */
	public ArrayList<HashMap<String, String>> getMapKey_KEY_HashMap(String Json_String,String KEY_MAP,String KEY_INDEX)
	{
		ArrayList<HashMap<String, String>> ArrayMap = new ArrayList<HashMap<String, String>>();
		JSONArray jsonArray = GetJSONArray_String(Json_String);
		// looping through all jsonarray nodes 
		for (int i = 0; i < jsonArray.length(); i++) {
			try {
				//create new JsonObject	
				JSONObject js = jsonArray.getJSONObject(i);
				if(js.getString(KEY_MAP).equals(KEY_INDEX)){
				// creating new HashMap
				HashMap<String, String> map = new HashMap<String, String>();
				String data;
				Log.e(JsonParser_course.class.toString(), "GetMap_full method----------------");
				data		=js.getString("subjectName");
				map.put(KEY_subjectName, data);
				//Log.e(JsonParser_course.class.toString(), "Get string subjectName");
				data		=js.getString("courseSize");
				map.put(KEY_courseSize, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseSize");
				data		=js.getString("lecturerName");
				map.put(KEY_lecturerName, data);
				Log.e(JsonParser_course.class.toString(), "Get string lecturerName" +data);
				data		=js.getString("facultyID");
				map.put(KEY_facultyID, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string facultyID");				
				data		=js.getString("subjectTheory");
				map.put(KEY_subjectTheory, data);
				//Log.e(JsonParser_course.class.toString(), "Get string subjectTheory");
				data		=js.getString("courseDay");
				map.put(KEY_courseDay, data);	
				Log.e(JsonParser_course.class.toString(), "Get string courseDay " +data);
				data		=js.getString("courseID");
				map.put(KEY_courseID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseID");
				data		=js.getString("subjectID");
				map.put(KEY_subjectID, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string subjectID");
				data		=js.getString("lecturerID");
				map.put(KEY_lecturerID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string lecturerID");
				data		=js.getString("courseStatus");
				map.put(KEY_courseStatus, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseStatus");
				data		=js.getString("courseTime");
				map.put(KEY_courseTime, data);
				Log.e(JsonParser_course.class.toString(), "Get string courseTime :"+data);	
				data		=js.getString("semesterID");
				map.put(KEY_semesterID, data);					
				//Log.e(JsonParser_course.class.toString(), "Get string semesterID");	
				data		=js.getString("courseType");
				map.put(KEY_courseType, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseType");	
				data		=js.getString("courseMaxSize");
				map.put(KEY_courseMaxSize, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseMaxSize");	
				data		=js.getString("roomID");
				map.put(KEY_roomID, data);
				Log.e(JsonParser_course.class.toString(), "Get string roomID:" +data);					
				data		=js.getString("subjectPractice");
				map.put(KEY_subjectPractice, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string subjectPractice");	
				data		=js.getString("semesterYear");
				map.put(KEY_semesterYear, data);
				//Log.e(JsonParser_course.class.toString(), "Get string semesterYear");
				data		=js.getString("semesterIndex");
				map.put(KEY_semesterIndex, data);									
				
				ArrayMap.add(map);	
				}
			} catch (Exception e) {
				// TODO: handle exception
				//Log.e(JsonParser_course.class.toString(), "Excetion getMapKey method");
			}
			
		}		
		return ArrayMap;
	}
	/**
	 Lấy những môn học Mở và đầy, Không lấy môn học đóng
	 */
	public ArrayList<HashMap<String, String>> getMap()
	{
		ArrayList<HashMap<String, String>> ArrayMap = new ArrayList<HashMap<String, String>>();
		JSONArray jsonArray = GetJSONArray_course();
		// looping through all jsonarray nodes 
		for (int i = 0; i < jsonArray.length(); i++) {			
			try {
				//create new JsonObject					
				JSONObject js = jsonArray.getJSONObject(i);	
				if( js.getString("courseStatus").equals("Mở")||js.getString("courseStatus").equals("Đầy")){
				// creating new HashMap
				HashMap<String, String> map = new HashMap<String, String>();
				String data;
				Log.e(JsonParser_course.class.toString(), "GetMap_full method----------------");
				data		=js.getString("subjectName");
				map.put(KEY_subjectName, data);
				//Log.e(JsonParser_course.class.toString(), "Get string subjectName");
				data		=js.getString("courseSize");
				map.put(KEY_courseSize, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseSize");
				data		=js.getString("lecturerName");
				map.put(KEY_lecturerName, data);
				Log.e(JsonParser_course.class.toString(), "Get string lecturerName" +data);
				data		=js.getString("facultyID");
				map.put(KEY_facultyID, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string facultyID");				
				data		=js.getString("subjectTheory");
				map.put(KEY_subjectTheory, data);
				//Log.e(JsonParser_course.class.toString(), "Get string subjectTheory");
				data		=js.getString("courseDay");
				map.put(KEY_courseDay, data);	
				Log.e(JsonParser_course.class.toString(), "Get string courseDay " +data);
				data		=js.getString("courseID");
				map.put(KEY_courseID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseID");
				data		=js.getString("subjectID");
				map.put(KEY_subjectID, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string subjectID");
				data		=js.getString("lecturerID");
				map.put(KEY_lecturerID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string lecturerID");
				data		=js.getString("courseStatus");
				map.put(KEY_courseStatus, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseStatus");
				data		=js.getString("courseTime");
				map.put(KEY_courseTime, data);
				Log.e(JsonParser_course.class.toString(), "Get string courseTime :"+data);	
				data		=js.getString("semesterID");
				map.put(KEY_semesterID, data);					
				//Log.e(JsonParser_course.class.toString(), "Get string semesterID");	
				data		=js.getString("courseType");
				map.put(KEY_courseType, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseType");	
				data		=js.getString("courseMaxSize");
				map.put(KEY_courseMaxSize, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseMaxSize");	
				data		=js.getString("roomID");
				map.put(KEY_roomID, data);
				Log.e(JsonParser_course.class.toString(), "Get string roomID:" +data);					
				data		=js.getString("subjectPractice");
				map.put(KEY_subjectPractice, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string subjectPractice");	
				data		=js.getString("semesterYear");
				map.put(KEY_semesterYear, data);
				//Log.e(JsonParser_course.class.toString(), "Get string semesterYear");
				data		=js.getString("semesterIndex");
				map.put(KEY_semesterIndex, data);
				//Log.e(JsonParser_course.class.toString(), "Get string facultyID");
				data		="Thu "+js.getString("courseDay")+ "Ca "+js.getString("courseTime")+"Phong "+js.getString("roomID");
				map.put(KEY_schedule, data);
//				String data;
//				// adding each child node to HashMap key => value
//				data		=js.getString("courseID")+"_"+js.getString("subjectName");
//				map.put(KEY_subjectName, data);
//				data		=js.getString("courseID");
//				map.put(KEY_courseID, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string subjectName");
//				data 		=js.getString("courseSize")+"/"+js.getString("courseMaxSize");
//				map.put(KEY_courseSize, data);	
//				//Log.e(JsonParser_course.class.toString(), "Get string courseMaxSize");
//				data	=js.getString("lecturerName");
//				map.put(KEY_lecturerName, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string lecturerName");
//				data		="Khoa :"+js.getString("facultyID");	
//				map.put(KEY_facultyID, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string facultyID");
//				data		="Thu "+js.getString("courseDay")+ "Ca "+js.getString("courseTime")+"Phong "+js.getString("roomID");
//				map.put(KEY_schedule, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string schedule");
//				data	="TCLT :"+js.getString("subjectTheory") +"TH :"+js.getString("subjectPractice");
//				map.put(KEY_subjectTheory, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string subjectTheory");
//				data		=js.getString("semesterYear");
//				map.put(KEY_semesterYear, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string semesterYear");
//				data		=js.getString("semesterIndex");
//				map.put(KEY_semesterIndex, data);	
//				//Log.e(JsonParser_course.class.toString(), "Get string semesterID");	
//				data		=js.getString("courseType");
//				map.put(KEY_courseType, data);	
//				//Log.e(JsonParser_course.class.toString(), "Get string courseType");	
//				data		=js.getString("courseMaxSize");
//				map.put(KEY_courseMaxSize, data);	
//				//Log.e(JsonParser_course.class.toString(), "Get string courseMaxSize");	
//				data		=js.getString("roomID");
//				map.put(KEY_roomID, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string roomID:" +data);					
//				data		=js.getString("subjectPractice");
//				map.put(KEY_subjectPractice, data);	
//				//Log.e(JsonParser_course.class.toString(), "Get string subjectPractice");	
//				data		=js.getString("semesterYear");
//				map.put(KEY_semesterYear, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string semesterYear");
//				data		=js.getString("semesterIndex");
//				map.put(KEY_semesterIndex, data);
				ArrayMap.add(map);
				}
			} catch (Exception e) {
				// TODO: handle exception
				//Log.e(JsonParser_course.class.toString(), "Exception getMap() method");
			}			
		}				
		return ArrayMap;
	}
	/**
	 Lấy những môn học Mở và đầy, Không lấy môn học đóng
	 */
	public ArrayList<HashMap<String, String>> getMap_Semester(String semester)
	{
		ArrayList<HashMap<String, String>> ArrayMap = new ArrayList<HashMap<String, String>>();
		JSONArray jsonArray = GetJSONArray_course_semester(semester);
		// looping through all jsonarray nodes 
		for (int i = 0; i < jsonArray.length(); i++) {			
			try {
				//create new JsonObject					
				JSONObject js = jsonArray.getJSONObject(i);	
				// creating new HashMap
				HashMap<String, String> map = new HashMap<String, String>();
				String data;
				Log.e(JsonParser_course.class.toString(), "GetMap_full method----------------");
				data		=js.getString("subjectName");
				map.put(KEY_subjectName, data);
				//Log.e(JsonParser_course.class.toString(), "Get string subjectName");
				data		=js.getString("courseSize");
				map.put(KEY_courseSize, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseSize");
				data		=js.getString("lecturerName");
				map.put(KEY_lecturerName, data);
				Log.e(JsonParser_course.class.toString(), "Get string lecturerName" +data);
				data		=js.getString("facultyID");
				map.put(KEY_facultyID, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string facultyID");				
				data		=js.getString("subjectTheory");
				map.put(KEY_subjectTheory, data);
				//Log.e(JsonParser_course.class.toString(), "Get string subjectTheory");
				data		=js.getString("courseDay");
				map.put(KEY_courseDay, data);	
				Log.e(JsonParser_course.class.toString(), "Get string courseDay " +data);
				data		=js.getString("courseID");
				map.put(KEY_courseID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseID");
				data		=js.getString("subjectID");
				map.put(KEY_subjectID, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string subjectID");
				data		=js.getString("lecturerID");
				map.put(KEY_lecturerID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string lecturerID");
				data		=js.getString("courseStatus");
				map.put(KEY_courseStatus, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseStatus");
				data		=js.getString("courseTime");
				map.put(KEY_courseTime, data);
				Log.e(JsonParser_course.class.toString(), "Get string courseTime :"+data);	
				data		=js.getString("semesterID");
				map.put(KEY_semesterID, data);					
				//Log.e(JsonParser_course.class.toString(), "Get string semesterID");	
				data		=js.getString("courseType");
				map.put(KEY_courseType, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseType");	
				data		=js.getString("courseMaxSize");
				map.put(KEY_courseMaxSize, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseMaxSize");	
				data		=js.getString("roomID");
				map.put(KEY_roomID, data);
				Log.e(JsonParser_course.class.toString(), "Get string roomID:" +data);					
				data		=js.getString("subjectPractice");
				map.put(KEY_subjectPractice, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string subjectPractice");	
				data		=js.getString("semesterYear");
				map.put(KEY_semesterYear, data);
				//Log.e(JsonParser_course.class.toString(), "Get string semesterYear");
				data		=js.getString("semesterIndex");
				map.put(KEY_semesterIndex, data);
				//Log.e(JsonParser_course.class.toString(), "Get string facultyID");
				data		="Thu "+js.getString("courseDay")+ "Ca "+js.getString("courseTime")+"Phong "+js.getString("roomID");
				map.put(KEY_schedule, data);
//				String data;
//				// adding each child node to HashMap key => value
//				data		=js.getString("courseID")+"_"+js.getString("subjectName");
//				map.put(KEY_subjectName, data);
//				data		=js.getString("courseID");
//				map.put(KEY_courseID, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string subjectName");
//				data 		=js.getString("courseSize")+"/"+js.getString("courseMaxSize");
//				map.put(KEY_courseSize, data);	
//				//Log.e(JsonParser_course.class.toString(), "Get string courseMaxSize");
//				data	=js.getString("lecturerName");
//				map.put(KEY_lecturerName, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string lecturerName");
//				data		="Khoa :"+js.getString("facultyID");	
//				map.put(KEY_facultyID, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string facultyID");
//				data		="Thu "+js.getString("courseDay")+ "Ca "+js.getString("courseTime")+"Phong "+js.getString("roomID");
//				map.put(KEY_schedule, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string schedule");
//				data	="TCLT :"+js.getString("subjectTheory") +"TH :"+js.getString("subjectPractice");
//				map.put(KEY_subjectTheory, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string subjectTheory");
//				data		=js.getString("semesterYear");
//				map.put(KEY_semesterYear, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string semesterYear");
//				data		=js.getString("semesterIndex");
//				map.put(KEY_semesterIndex, data);	
//				//Log.e(JsonParser_course.class.toString(), "Get string semesterID");	
//				data		=js.getString("courseType");
//				map.put(KEY_courseType, data);	
//				//Log.e(JsonParser_course.class.toString(), "Get string courseType");	
//				data		=js.getString("courseMaxSize");
//				map.put(KEY_courseMaxSize, data);	
//				//Log.e(JsonParser_course.class.toString(), "Get string courseMaxSize");	
//				data		=js.getString("roomID");
//				map.put(KEY_roomID, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string roomID:" +data);					
//				data		=js.getString("subjectPractice");
//				map.put(KEY_subjectPractice, data);	
//				//Log.e(JsonParser_course.class.toString(), "Get string subjectPractice");	
//				data		=js.getString("semesterYear");
//				map.put(KEY_semesterYear, data);
//				//Log.e(JsonParser_course.class.toString(), "Get string semesterYear");
//				data		=js.getString("semesterIndex");
//				map.put(KEY_semesterIndex, data);
				ArrayMap.add(map);				
			} catch (Exception e) {
				// TODO: handle exception
				//Log.e(JsonParser_course.class.toString(), "Exception getMap() method");
			}			
		}				
		return ArrayMap;
	}
	/**
	 Lấy những môn học Mở và đầy, đóng
	 */
	public ArrayList<HashMap<String, String>> getMap_full()
	{
		ArrayList<HashMap<String, String>> ArrayMap = new ArrayList<HashMap<String, String>>();
		JSONArray jsonArray = GetJSONArray_course();
		// looping through all jsonarray nodes 
		for (int i = 0; i < jsonArray.length(); i++) {			
			try {
				//create new JsonObject					
				JSONObject js = jsonArray.getJSONObject(i);					
				// creating new HashMap
				HashMap<String, String> map = new HashMap<String, String>();	
				String data;
				Log.e(JsonParser_course.class.toString(), "GetMap_full method----------------");
				data		=js.getString("subjectName");
				map.put(KEY_subjectName, data);
				//Log.e(JsonParser_course.class.toString(), "Get string subjectName");
				data		=js.getString("courseSize");
				map.put(KEY_courseSize, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseSize");
				data		=js.getString("lecturerName");
				map.put(KEY_lecturerName, data);
				Log.e(JsonParser_course.class.toString(), "Get string lecturerName" +data);
				data		=js.getString("facultyID");
				map.put(KEY_facultyID, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string facultyID");				
				data		=js.getString("subjectTheory");
				map.put(KEY_subjectTheory, data);
				//Log.e(JsonParser_course.class.toString(), "Get string subjectTheory");
				data		=js.getString("courseDay");
				map.put(KEY_courseDay, data);	
				Log.e(JsonParser_course.class.toString(), "Get string courseDay " +data);
				data		=js.getString("courseID");
				map.put(KEY_courseID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseID");
				data		=js.getString("subjectID");
				map.put(KEY_subjectID, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string subjectID");
				data		=js.getString("lecturerID");
				map.put(KEY_lecturerID, data);
				//Log.e(JsonParser_course.class.toString(), "Get string lecturerID");
				data		=js.getString("courseStatus");
				map.put(KEY_courseStatus, data);
				//Log.e(JsonParser_course.class.toString(), "Get string courseStatus");
				data		=js.getString("courseTime");
				map.put(KEY_courseTime, data);
				Log.e(JsonParser_course.class.toString(), "Get string courseTime :"+data);	
				data		=js.getString("semesterID");
				map.put(KEY_semesterID, data);					
				//Log.e(JsonParser_course.class.toString(), "Get string semesterID");	
				data		=js.getString("courseType");
				map.put(KEY_courseType, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseType");	
				data		=js.getString("courseMaxSize");
				map.put(KEY_courseMaxSize, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string courseMaxSize");	
				data		=js.getString("roomID");
				map.put(KEY_roomID, data);
				Log.e(JsonParser_course.class.toString(), "Get string roomID:" +data);					
				data		=js.getString("subjectPractice");
				map.put(KEY_subjectPractice, data);	
				//Log.e(JsonParser_course.class.toString(), "Get string subjectPractice");	
				data		=js.getString("semesterYear");
				map.put(KEY_semesterYear, data);
				//Log.e(JsonParser_course.class.toString(), "Get string semesterYear");
				data		=js.getString("semesterIndex");
				map.put(KEY_semesterIndex, data);
								
				ArrayMap.add(map);				
			} catch (Exception e) {
				// TODO: handle exception
				//Log.e(JsonParser_course.class.toString(), "Exception getMap() method");
			}			
		}				
		return ArrayMap;
	}
	/**
	Put data to Google App Engine
	*/
	public String PutDataRegCourse(String courseID, String studentID, String oper){
    	DefaultHttpClient hc=new DefaultHttpClient();
    	ResponseHandler <String> res=new BasicResponseHandler();
    	HttpPost postMethod=new HttpPost("http://uitstudentmanagement.appspot.com/regCourse");
    	List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    	//Log.e(JsonParser_course.class.toString(), "Put Data 1");
    	nameValuePairs.add(new BasicNameValuePair("courseID", courseID));
    	//Log.e(JsonParser_course.class.toString(), "Put Data 2");
    	nameValuePairs.add(new BasicNameValuePair("studentID", studentID));
    	//Log.e(JsonParser_course.class.toString(), "Put Data 3");
    	nameValuePairs.add(new BasicNameValuePair("oper", oper));
    	try {
			postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}  
    	try {
			String response=hc.execute(postMethod,res);
			return response;
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return "flase";
    }
}
